import { AmqpClientService } from '@app/amqp-client';
import { CacheService } from '@app/cache';
import { ConfigureService } from '@app/configure';
import { Injectable } from '@nestjs/common';
import * as dayjs from 'dayjs';

@Injectable()
export class AmqpService {
	private DEVICE_MESSAGE_LIST:string
	constructor(
		private readonly amqpClient:AmqpClientService,
		private readonly config:ConfigureService,
		private readonly cache:CacheService,
	) {
		this.DEVICE_MESSAGE_LIST = this.config.get('DEVICE_MESSAGE_LIST')
		amqpClient.on('message', this.message)
	}

	public message(context) {
		var msg = context.message;
		const topic = msg.application_properties.topic
		const content = Buffer.from(msg.body.content).toString()
		const messageId = msg.message_id

		const time = dayjs().unix()

		try {
			if(topic.indexOf('/as/mqtt/status') == 0) {
				const deviceId = Number(msg.deviceName)
			}


		} catch (error) {
			
		}
        
        context.delivery.accept();
	}
}
